package report5;

import java.util.Scanner;

/**
 * 启动类
 *
 * @author zouran
 * createDate：1023/5/25  18:10
 */
public class Main {
    public static void exe() {
        Scanner scanner = new Scanner(System.in);
        int length;
        while (true) {
            System.out.println("请输入磁盘寻道序列长度（10-20，含端点）：");
            length = scanner.nextInt();
            if (length > 20 || length < 10) {
                System.out.println("您输入的磁盘寻道序列长度超出给定范围，请重新输入10-20（含端点）的数字：");
            } else break;
        }
        Calculate calculate = new Calculate(length);
        while (true) {
            calculate.getRequestList();
            System.out.println("请选择要执行的磁盘寻道算法：1、FCFS；2、SSTF；3、SCAN；4、CSACN");
            int choice = scanner.nextInt();
            while (true) {
                if (choice > 5 || choice < 1) {
                    System.out.println("您输入的选择超出给定范围，请重新输入1-5（含端点）的数字");
                    choice = scanner.nextInt();
                } else break;
            }
            switch (choice) {
                case 1:
                    calculate.FCFS();
                    break;
                case 2:
                    calculate.SSTF();
                    break;
                case 3: {
                    System.out.println("请继续选择当前磁头运动方向：1、由低到高；2、由高到低");
                    int direction = scanner.nextInt();
                    if (direction == 1) calculate.SCAN_OR_CSCAN(Calculate.SCAN_UP, Calculate.SCAN);
                    else calculate.SCAN_OR_CSCAN(Calculate.SCAN_DOWN, Calculate.SCAN);
                    break;
                }
                case 4: {
                    System.out.println("请继续选择当前磁头运动方向：1、由低到高；2、由高到低");
                    int direction = scanner.nextInt();
                    if (direction == 1) calculate.SCAN_OR_CSCAN(Calculate.SCAN_UP, Calculate.CSCAN);
                    else calculate.SCAN_OR_CSCAN(Calculate.SCAN_DOWN, Calculate.CSCAN);
                    break;
                }
            }
            System.out.println("本次计算已完成，请选择：1、继续尝试其他算法；2、更换数据；3、结束程序");
            int back = scanner.nextInt();
            switch (back) {
                case 1:
                    break;
                case 2:
                    calculate = new Calculate(length);
                    break;
                case 3:
                    System.exit(0);
            }
        }
    }

    public static void main(String[] args) {
        exe();
    }
}
